//        1.在Person类里增加两个属性，两个方法，定义两个构造方法，在另外的main中测试
//
//        2.定义狗类Dog, 2个属性，两个方法 ，两个构造函数，在另外的main中测试
//
//        3.在Person类增加Dog属性，描述人可以拥有一只狗。
//
//        4.继承Person实现Diver类，增加相应属性和方法，创建对应并调用。
//
//        5.在Main类中定义一个可以存放5本书的数组
//        Book[] books = new Book[5];
//        创建这个Book类的5个对象放到books中，用循环打印每本书的信息。

class Dog{
    public String color;
    public int age;

    public Dog() {
        this.color = "黑色";
        this.age = 18;
    }

    public Dog(String color, int age){
        this.color = color;
        this.age = age;
    }

    public void eatFood(){
        System.out.println("这只" + this.color + "狗正在吃狗粮");
    }

    public void goSleep(){
        System.out.println("这只" + this.color + "狗正在睡觉");
    }

    @Override//覆盖toString来在main中进行有效输出狗的信息
    public String toString() {
        return "Dog{" +
                "color='" + color + '\'' +
                ", age=" + age +
                '}';
    }
}

class Person{
    public String name;
    public int age;
    public Dog dog;//添加Dog属性

    public Person() {
        this.name = "Pake";
        this.age = 18;
        this.dog = new Dog();//构造函数中初始化对象狗
    }

    public Person(String name, int age,Dog dog){
        this.name = name;
        this.age = age;
        this.dog = dog;
    }

    public void doWork(){
        System.out.println(this.name + "正在做作业");
    }

    public void goSleep(){
        System.out.println(this.name + "正在睡觉");
    }

}

class Diver extends Person{
    String diverNum;
    int divingAge;

    public Diver(String diverNum, int divingAge) {
        this.diverNum = diverNum;
        this.divingAge = divingAge;
    }

    public Diver(String name, int age, Dog dog, String diverNum, int divingAge) {
        super(name, age, dog);
        this.diverNum = diverNum;
        this.divingAge = divingAge;
    }

    public void dive(){
        System.out.println(this.name + "正在潜水");
    }
}

class Book {
    private String title;
    private String author;
    private int pages;

    public Book(String title, String author, int pages) {
        this.title = title;
        this.author = author;
        this.pages = pages;
    }

    public String getTitle() {
        return title;
    }

    public String getAuthor() {
        return author;
    }

    public int getPages() {
        return pages;
    }

    @Override
    public String toString() {
        return "Book{" +
                "title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", pages=" + pages +
                '}';
    }
}

public class Demo1 {
    public static void main(String[] args) {
//        Person person1 = new Person();
//        person1.doWork();
//        person1.goSleep();
//        System.out.println("======");
//        Person person2 = new Person("Siwen",19,new Dog("大黑",5));
//        person2.doWork();
//        person2.goSleep();
//        System.out.println(person2.name + "的狗"+ person2.dog);
//        System.out.println("======");
//        Dog dog1 = new Dog();
//        dog1.eatFood();
//        System.out.println(dog1.color);
//        dog1.goSleep();
//        System.out.println("======");
//        Dog dog2 = new Dog("大黄",12);
//        dog2.eatFood();
//        dog2.goSleep();
        System.out.println("======");
        Diver diver = new Diver("莱恩",20,new Dog("斑点",3),"代号q",5);
        diver.doWork();
        diver.goSleep();
        diver.dive();
        System.out.println("潜水员" + diver.name + "有一只" + diver.dog +
                "，使用的编号是" + diver.diverNum + "，潜水了" + diver.divingAge + "年");
        System.out.println("======");

        Book[] books = new Book[5];

        // 初始化书籍对象
        books[0] = new Book("M13", "伊丽莎白", 1168);
        books[1] = new Book("Asval", "百战", 416);
        books[2] = new Book("Dingo", "马卡洛夫", 464);
        books[3] = new Book("Jak12", "范利肯", 694);
        books[4] = new Book("Kilo141", "海伦", 416);

        for (int i = 0; i < books.length; i++) {
            System.out.println("书籍信息 No." + (i+1) + ": " + books[i]);
        }
    }
}



